get XScrollBox(2,"Choose one of these:",card field "scroller","Help")
go this card
if it is "Help" then
answer "You pushed the 'Help' button."
else if it is empty then
answer "You pushed the 'Cancel' button."
else
answer "Your choice was: " & it
end if
end mouseUp
-- part 5 (field)
-- low flags: 01
-- high flags: 2007
-- rect: left=17 top=31 right=286 bottom=382
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: Documentation
-- part 6 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=299 top=298 right=320 bottom=438
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Show LSC Source
----- HyperTalk script -----
on mouseUp
get the visible of card field "source"
set the visible of card field "source" to not it
if it is false then
set the name of me to "Hide LSC Source"
else
set the name of me to "Show LSC Source"
end if
end mouseUp
-- part 7 (field)
-- low flags: 81
-- high flags: 0007
-- rect: left=18 top=31 right=290 bottom=489
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: Source
-- part contents for card part 2
----- text -----
able
baker
charlie
dog
ernest
fox
gamma
horse
ice cream
jumping jack flash
knockwurst
liver
monkey
no way, jose
occularity
penelope
qwerty
rapscallion
salubrious
twinkle toes
underwhelmed
vermin
wascally wabbit
yokel
zenzational
-- part contents for card part 5
----- text -----
XScrollBox version 1.7
Roger Brown
XScrollBox is a HyperCard XFCN that creates a scrolling selection dialog box from any multi-lined container. Each line of the container is made into a selection line in the dialog. Only one line can be selected.
The return value has two items: the number of the selection and the text of the selection. These are separated by commas as in normal HyperCard format.
Selection can be made by :
1. double-clicking on a line.
2. single-clicking on a line, then pressing the OK button.
3. single-clicking on a line, then pressing the Return key.
4. typing the first letter(s) of a selection, then doing 1,2, or 3.
(Note: type selection assumes that the lines are ordered
alphabetically)
5. scrolling with up and down arrow keys, then doing 1,2 or 3.
If the Cancel button is pressed, a null string is returned.
It requires that the DITL and DLOG resources (1345) packaged
with it are in the stack.
The dialog is centered on the screen and sized to hold the width of the longest line and/or the prompt line, whichever is widest. It will not overrun the width of a Mac+ screen.
INVOKING XScrollBox
get XScrollBox(first,prompt,container,userButton)
where first is a default selection in the list - either a number or
a text string (0 if none).
prompt is a string to prompt the user. This appears at the
top of the dialog box.
container is any hypercard container (field, variable),
presumed to be multi-lined.
UserButton is the name for an optional author specified
button. If this button is pressed, its name is
returned further processing by the script.
EXAMPLE
ex. get XScrollBox(1,"Choose:",card field 1,"Help")
if OK is pressed, returns : 1,text of line 1 of card field 1
REVISION HISTORY
1.1 center dialog box on any size screen
1.2 - add selection scrolling by typing and by cursor keys
1.3 - add text of chosen item to return value
1.4 - 3/2/88 add optional user button
1.6 - 5/12/89 fixed problem with selecting the first item the
first time when type-selecting. Fixed problem where typing
an item exactly selects the one after it.
1.7 - 5/15/89 made it compile under LSC 3.0.
-- part contents for card part 7
----- text -----
/* XScrollBox1.7.c */
/* © Trustees of Dartmouth College */
/* written in LightSpeed C © Think Technologies, Inc */
/* by Roger Brown 3/2/88 Courseware Development group */
/* This is a HyperCard XFCN that creates a scrolling selection dialog box from
any multi-lined container. Syntax is:
get XScrollBox(first,prompt,container,userButton)
ex. get XScrollBox(1,"Choose:",card field 1,"Help")
returns: 1,text of line 1 of card field 1
where first is a default selection in the list - either a number
or a text string (0 if none).
prompt is a string to prompt the user. This appears at the
top of the dialog box.
container is any hypercard container (field, variable), presumed to be
multi-lined.
UserButton is the name for an optional author specified button.
If this button is pressed, its name is returned
for further processing by the script.
Each line of the container is made into a selection line in the
dialog. Only one line can be selected.
The return value has two items: the number of the selection and the text of
the selection. These are separated by commas as in normal HyperCard format.
Selection can be made by:
1. double-clicking on a line.
2. single-clicking on a line, then pressing the OK button.
3. single-clicking on a line, then pressing the Return key.
4. typing the first letter(s) of a selection, then doing 1,2, or 3.
(Note: type selection assumes that the lines are ordered alphabetically)
5. scrolling with up and down arrow keys, then doing 1,2 or 3.
If the Cancel button is pressed, a null string is returned.
It requires that the DITL and DLOG resources packaged with it are in the stack.
The dialog box is centered in the card window.
To compile: create a project with this and MacTraps. Build as code resource type
XFCN, ID 1345, name XScrollBox.
*/
/* version 1.7: LSC 3.0 compiled 5/15/89 */
/* version 1.6: fixed problem with selecting the first item the first time
when type-selecting. Fixed problem where typing an item exactly selects
the one after it.
*/
#include "stddata_ctype.c"
#include "QuickDraw.h"
#include "EventMgr.h"
#include "WindowMgr.h"
#include "ResourceMgr.h"
#include "ControlMgr.h"
#include "DialogMgr.h"
#include "strings.c"
#include "ListMgr.h"
#include "ToolboxUtil.h"
#include "HyperXCmd.h"
#include "XCmdGlue.inc.c"
#include "SetUpA4.h"
#define FALSE 0
#define TRUE !FALSE
/* globals */
#define kOKbutton 1
#define kCancel 2
#define kPrompt 3
#define kListItem 4
#define kOutliner 5
#define kUserButton 6
#define kTyping 99
int kScrollBarWidth = 15;
int kStdLDEF = 0;
int kDialogId = 1345;
int kStringListId = 1345;
int gCellWidth;
int gCellHeight = 16;
Rect dialogRect,listRect,cardRect;
ListHandle theList;
DialogPtr theListDialog;
Str255 theResult,userButton;
long theStartWith;
Str255 startString;
char startIsString;
Handle resultHandle;
CursHandle theCursor;
char collector[32];
int charPos;
long charTime;
XCmdBlockPtr gParamPtr;
/* return max of 2 integers */
max(a,b)
int a,b;
{
if (a>b) return a;
return b;
}
/* return min of 2 integers */
min(a,b)
{
if (a<b) return a;
return b;
}
/* Get HyperCard comma delimited item i from item list string s. */
int GetHCItem(s,i)
char *s;
int i;
{
int c,len,count,j;
char temp[32];
long it;
count = j = 0;
len = strlen(s);
for (c=0;c<len;c++) {
if (s[c]==',') {
count = count + 1;
if (count==i) break;
j = 0;
}
else {
temp[j] = s[c];
j++;
if (c==(len-1)) { /* last item, no comma */
count = count+1;
break;
}
}
}
if (count < i) strcpy(temp,""); /* no item there */
temp[j] = 0;
CtoPstr(temp);
StringToNum(temp,&it);
return (int)it;
}
/* Get the coordiates of the HyperCard card window so we can center the dialog on it. */
GetCardRect(paramPtr,itsRect)
XCmdBlockPtr paramPtr;
Rect *itsRect;
{
Handle theResult;
long len;
Str255 str;
int i;
strcpy(str,"the rect of card window");
CtoPstr((char *)str);
theResult = EvalExpr(paramPtr,str);
len = GetHandleSize(theResult);
HLock(theResult);
BlockMove(*theResult,str,len);
HUnlock(theResult);
DisposHandle(theResult);
itsRect->left = GetHCItem(str,1);
itsRect->top = GetHCItem(str,2);
itsRect->right = GetHCItem(str,3);
itsRect->bottom = GetHCItem(str,4);
}
/* user item in dialog box to outline the default (ok) button */